clear all


use "pb replication study 2.dta"

***create fig 3

collapse (mean) meansteal= steal2 (sd) sdsteal=steal2 (count) n=steal2, by(steal_condition)

generate histeal = meansteal + invttail(n-1,0.025)*(sdsteal / sqrt(n))
generate lowsteal = meansteal - invttail(n-1,0.025)*(sdsteal / sqrt(n))

generate pidcond = 2 if steal_cond==4 
replace  pidcond = 5 if steal_cond==3 
replace  pidcond = 8 if steal_cond==1 
replace  pidcond = 11 if steal_cond==2
sort pidcond
list pidcond steal_cond

format meansteal %3.2f

twoway (bar meansteal pidcond,color(gs1) mlabel(meansteal) mlabposition(2) mlabcolor(black)) ///
       (rcap histeal lowsteal pidcond), ///
       xlabel( 2 "Dems Expand" 5 "Reps Expand" 8 "Reps Restrict" 11 "Dems Restrict", noticks) ///
       xtitle("Treatment") ytitle("Proportion say tactic was attempt to steal election") ///
		ylab(0(.1)1, angle(horizontal)) ///
		graphregion(fcolor(white)) ///
	   legend(off)
	
	    graph save figure3, replace
 
clear all
use "pb replication study 2.dta"

***create fig 4

****To create graphs without indep
drop if pid3==3

collapse (mean) meansteal= steal2 (sd) sdsteal=steal2 (count) n=steal2, by(pid3 steal_condition)

generate histeal = meansteal + invttail(n-1,0.025)*(sdsteal / sqrt(n))
generate lowsteal = meansteal - invttail(n-1,0.025)*(sdsteal / sqrt(n))

	   
generate pidcond = pid3    if steal_cond == 4
replace  pidcond = pid3+4    if steal_cond == 3 
replace  pidcond = pid3+8    if steal_cond == 1 
replace  pidcond = pid3+12    if steal_cond == 2
sort pidcond
list pidcond steal_cond pid3, sepby(steal_cond)

format meansteal %3.2f
	   
twoway (bar meansteal pidcond if pid3==1,color(gs1) mlabel(meansteal) mlabposition(10) mlabcolor(black)) ///
       (bar meansteal pidcond if pid3==2,color(gs4) mlabel(meansteal) mlabposition(2) mlabcolor(black)) ///
       (rcap histeal lowsteal pidcond), ///
       legend(order(1 "Dems" 2 "Reps")) ///
       xlabel(-.05 " " 2 "Dems Expand" 6 "Reps Expand" 10 "Reps Restrict" 13 "Dems Restrict", noticks) ///
       xtitle("Treatment Type") ytitle("Proportion say tactic was attempt to steal election") ///
	   ylab(0(.1)1, angle(horizontal)) ///
	   graphregion(fcolor(white)) 
	   
	   graph save figure4, replace

clear all
use "pb replication study 2.dta"

*second column in table in appendix 3

gen dem=rep3
recode dem 1=1 2/3=0

gen rep=rep3
recode rep 1/2=0 3=1

logit steal2 c.dem##c.demcheat c.rep##c.demcheat add

*create fig 5b, same model as above, but specified differently to get margins

logit steal2 i.rep3##c.demcheat add

margins, at(demcheat=(0 1) rep3=(1 2 3))
marginsplot, ///
 plot1opts(msymbol(O)  mcolor(gs1)  lpattern(l) lcolor(gs1)) ///
 plot2opts(msymbol(T)  mcolor(gs1)  lpattern(-) lcolor(gs1)) ///
  plot3opts(msymbol(S)  mcolor(gs1)  lpattern(_-) lcolor(gs1)) ///
   ciopts(lcolor(black)) ///
      xlabel( .05 "Reps cheat" .95 "Dems cheat", noticks) ///
      ytitle("Predicted probability was attempt to steal election") ///
	   xtitle("") ///
		ylab(0(.1)1, angle(horizontal)) ///
		title("") ///
	   graphregion(fcolor(white)) 

	   graph save figure5b, replace


margins, at(add=(0 1))


***create fig 6b

recode steal_cond 1 3=1 2 4=0
collapse (mean) meansteal= steal2 (sd) sdsteal=steal2 (count) n=steal2, by(pid3 steal_condition)



generate histeal = meansteal + invttail(n-1,0.025)*(sdsteal / sqrt(n))
generate lowsteal = meansteal - invttail(n-1,0.025)*(sdsteal / sqrt(n))


generate pidcond = 1 if steal_cond==0 & pid3 == 1
replace pidcond = 2 if steal_cond==1 & pid3 == 2
replace pidcond = 4 if steal_cond==0 & pid3 == 3
replace pidcond = 5 if steal_cond==1 & pid3 == 3
replace pidcond = 7 if steal_cond==0 & pid3 == 2
replace pidcond = 8 if steal_cond==1 & pid3 == 1

sort pidcond
list pidcond steal_cond pid3, sepby(pid3)

format meansteal %3.2f

twoway (bar meansteal pidcond if steal_cond==1,color(gs1) mlabel(meansteal) mlabposition(2) mlabcolor(black)) ///
       (bar meansteal pidcond if steal_cond==0,color(gs4) mlabel(meansteal) mlabposition(2) mlabcolor(black)) ///
       (rcap histeal lowsteal pidcond), ///
       legend( order(1 "Dems cheat" 2 "Reps cheat") ) ///
       xlabel( 1.5 "Own Party Cheats" 4.5 "Independents" 7.5 "Other Party Cheats", noticks) ///
      ytitle("Proportion say tactic was attempt to steal election") ///
	   xtitle("") ///
	    ylab(0(.1)1, angle(horizontal)) ///
	   graphregion(fcolor(white)) 
	   
	   graph save figure6b, replace


